﻿using Core.Helper;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace HandyWpf.Validations
{
    public class IpValidation : ValidationRule
    {
        private IpHelper ipHelper = new IpHelper();
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if(value != null)
            {
                string ip = value.ToString();
                if(ipHelper.ValidateIPAddress(ip))
                {
                    return ValidationResult.ValidResult;
                }
                else
                {
                    return new ValidationResult(false, "ip格式不正确！");
                }
            }
            return new ValidationResult(false, "ip不能为空！");
        }
    }
}
